<template>
    <div class="center">
        <!-- 个性化 -->
        <!-- 年龄
        性别
        兴趣爱好
        游戏 -->

        <el-form :model="form" label-width="auto" style="max-width: 400px; padding: 30px;position: relative;">
            <img src="../assets/images/loading.png" alt="" width="40" height="40" style="position: absolute;bottom: 0;right: 0;">
            <div class="titie">设置一下 更懂你</div>
            <el-form-item label="年龄">
                <el-input v-model="form.name" />
            </el-form-item>
            <el-form-item label="性别">
                <el-select v-model="form.region" placeholder="">
                    <el-option label="男" value="shanghai" />
                    <el-option label="女" value="beijing" />
                </el-select>
            </el-form-item>
            <el-form-item label="兴趣爱好">
                <el-button plain @click="dialogVisible = true">
                    Click to open the Dialog
                </el-button>

            </el-form-item>

            <el-form-item>
                <div class="form_btn">
                    <div style="width: 68px;">

                    </div>
                    <el-button type="primary" @click="onSubmit" class="onSubmit">进入</el-button>

                    <span @click="skip" class="skip">跳过</span>
                </div>
            </el-form-item>
        </el-form>
        <div v-if="dialogVisible" class="fond">
            <div class="tap">
                <div v-for="(item, index) in tap_data" :key="index" class="tap_box">
                    <h3 class="tap_left">{{ item.name }}</h3>
                    <ul class="tap_right">
                        <!-- <li v-for="(subItem, subIndex) in item.data" :key="subIndex">{{ subItem.name }}</li> -->
                        <div class="tap_options" v-for="(subItem, subIndex) in item.data" :key="subIndex" @click="options(subItem)">
                            <img class="icon" src="../assets/images/loading.png" alt="">
                            <div class="icon_status">
                                <img v-if="subItem.status"  src="../assets/1x/选择.png" alt="" >
                            </div>
                            <span class="tap_text">{{ subItem.name }}</span>
                        </div>
                    </ul>
                </div>
                <div>{{  this.text}}</div>
            </div>
            <div class="tap_botton">
                <el-button plain @click="select()" >
                    选好了
                </el-button>
                <el-button plain @click="clear()">
                    算了
                </el-button>
            </div>
        </div>
    </div>
</template>

<script>

export default {
    data() {
        return {
            text:null,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tap_data: [
                {
                    id: 1,
                    name: "游戏",
                    data: [{ name: "原神", status:0 }, { name: "王者",status:0 }]
                },
                {
                    id: 1,
                    name: "动漫",
                    data: [{ name: "鬼灭之刃", status:0 }, { name: "间谍过家家", status:0 }]
                },
            ],
            dialogVisible: false
        }
    },
    methods: {
        onSubmit() {
            // 提交个性化设置，进入主页
            this.$router.push("/IndexBook")
            // 接口
        },
        // 跳过此页面进入主页
        skip() {
            this.$router.push("/IndexBook")
        },
        // 爱好勾选事件
        options(data){
            this.text = data
            data.status = !data.status
            
        },
        // 选择兴趣爱好确定事件
        select(){
            this.dialogVisible = false
            // 事件接口
        },
        // 选择兴趣爱好的取消事件
        clear(){
            // this.dialogVisible = false
            for (let i = 0; i < this.tap_data.length; i++) {
                const category = this.tap_data[i];
                for (let j = 0; j < category.data.length; j++) {
                    const item = category.data[j];
                    item.status = 0
                    console.log(`name: ${item.name}, status: ${item.status}`);
                }
            }
        }
    }
}
</script>

<style lang="less" scoped>
.center {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;

    .el-form {
        padding: 10px;
        border-radius: 8px;
        box-shadow: 1px 1px 5px rgb(222, 222, 222);
        overflow: hidden;

        .titie {
            width: 100%;
            height: 50px;
            font-size: 20px;
            text-align: center;
        }

        .form_btn {
            width: 100%;
            display: flex;
            justify-content: left;
        }

        .onSubmit {
            width: 80px;
            height: 30px;
        }

        .skip {
            margin-left: 10px;
            top: 6px;
            left: 180px;
            font-size: 12px;
            padding: 0;
            color: #7d7d7d;
            border: 0 solid #000;

        }

        .skip:hover {
            color: #000000;
        }
    }

    .fond {
        width: 800px;
        height: 500px;
        background-color: #000000;
        position: fixed;

        .tap {
            width: 100%;
            height: 90%;
            background-color: #ffffff;
            .tap_box{
                display: flex;
            }
            .tap_left{
                width: 10%;
                display: flex;
                align-items: center;
                justify-content: center;
                background-color: #dbdbdb;
            }
            .tap_right{
                width: 90%;
                display: flex;
                
                .tap_options{
                    width: 60px;
                    display: inline-block;
                    align-items: center;
                    display: flex;
                    flex-direction: column;
                    padding: 10px;

                    .icon{
                        position: relative;
                        width: 40px;
                        height: 40px;
                        border-radius: 4px;
                    }
                    .icon_status{
                        width: 40px;
                        height: 40px;
                        display: flex;
                        justify-content: flex-end;
                        align-items: flex-end;
                        position: absolute;
                        img{
                            width: 20px;
                        height: 20px;
                        }
                    }
                    .tap_text{
                        margin-top: 5px;
                        font-size: 12px;
                        text-align: center;
                    }
                }
                .tap_option:hover{
                        box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.452);
                        width: 100px;
                    }
            }
        }

        .tap_botton {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 10%;
        }
    }
}
</style>